package cgb2202.recruitment01.mapper;

import cgb2202.recruitment01.entity.EmpInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

/*此接口中sql字段需要根据empInfo表格和相关实体类,控制器进行调整*/
@Mapper
public interface EmpInfoMapper {
    //users 和user_info两表联查 通过email账号查个人信息反馈到页面 users.email = #{email} and
    @Select("SELECT user_info.name,user_info.birthday,user_info.education,user_info.college,user_info.major,user_info.work FROM users,user_info WHERE  users.id=user_info.uid")
    EmpInfo getEmpInfoByEmail(String email);

    //插入个人信息反馈数据库
    @Insert("insert into user_info values(null,#{uid},#{empInfo.name},#{empInfo.birthday},#{empInfo.education},#{empInfo.college},#{empInfo.major},#{empInfo.work},0)")
    void insertEmpInfo(@Param(value = "uid") int uid,@Param(value = "empInfo") EmpInfo empInfo);

    //修改个人信息反馈数据库
    @Update("update user_info set name=#{empInfo.name},birthday=#{empInfo.birthday},education=#{empInfo.education},college=#{empInfo.college},major=#{empInfo.major},work=#{empInfo.work} where uid=#{uid}")
    void updateEmpInfo(@Param(value = "uid")int uid,@Param(value = "empInfo")EmpInfo empInfo);

    //查询是否存在个人信息
    @Select("select count(*) from user_info where uid=#{id}")
    int selectByUid (int id);

    //用于给AdminController调用删除信息
    @Delete("delete from emp_info where id=#{id}")
    void deleteById(int id);

    //用于给AdminController调用通过个人信息审核
    @Update("update emp_info set pass = 1 where id=#{id}")
    void passCheckById(int id);

    //用于给AdminController调用驳回个人信息审核
    @Update("update emp_info set pass = 2 where id=#{id}")
    void rejectCheckById(int id);

    //用于给Admin选取个人信息
    @Select("select from emp_info order by pass")
    List<EmpInfo> adminSelect();
}
